//
//  WHSettingTableView.m
//  WHPersonalData
//
//  Created by mac on 2018/1/2.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "WHMeTableView.h"
#import "SDAutoLayout.h"
#import "WHMeTableViewHeaderCell.h"
#import "WHMeModel.h"
#import "UIView+Rounded.h"

static NSString  *tableViewCell = @"tableViewCell";

@interface WHMeTableView ()<UITableViewDelegate,UITableViewDataSource>
@end
@implementation WHMeTableView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame style:UITableViewStylePlain];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.delegate   = self;
        self.dataSource = self;
    }
    return self;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.models.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell  * cell;
    WHMeModel*wHMeModel = self.models[indexPath.row];
    if (indexPath.row==0)
    {
       WHMeTableViewHeaderCell*tableViewCell =[WHMeTableViewHeaderCell cellWithTableView:tableView];
        tableViewCell.wHMeModel =wHMeModel;
        cell =tableViewCell;
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, ScreenW);
       
    }else if(wHMeModel.titleString.length<=0){
        cell=[tableView dequeueReusableCellWithIdentifier:tableViewCell];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCell];
        }
        cell.frame = CGRectMake(0, 0, ScreenW,60);
        cell.backgroundColor = [UIColor whiteColor];
        cell.separatorInset = UIEdgeInsetsMake(0, cell.frame.size.width, 0, 0);
    }else
    {
        cell=[tableView dequeueReusableCellWithIdentifier:tableViewCell];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCell];
        }
        NSString*string = wHMeModel.titleString;
        cell.imageView.image =     [UIImage imageNamed:wHMeModel.imagePath];
        cell.textLabel.text = string;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font  = [UIFont systemFontOfSize:15*WidthScale>17?17:15*WidthScale];
        cell.frame = CGRectMake(20, 0, ScreenW-40,60);
        cell.backgroundColor = [UIColor whiteColor];
       
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, ScreenW);
        if(indexPath.row == 1){//画圆角
            [UIView setViewRoundedWithRad:10 byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight view:cell];
        }else if (indexPath.row ==self.models.count-1)
        {
            [UIView setViewRoundedWithRad:10 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight view:cell];
        }
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0)
    {
    return ScreenH/5;
    }
    return 70;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (_meTableViewDelegate &&[_meTableViewDelegate respondsToSelector:@selector(meTableViewChickIndexPath:)])
    {
        [_meTableViewDelegate meTableViewChickIndexPath:indexPath];
    }
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}
@end
